// 在React中，组件名必须大写
import { HashRouter, BrowserRouter, Routes, Route, Link } from "react-router-dom";
import Layout from "@/pages/layout/index";
import Login from "@/pages/login/index";
import Dashboard from "@/pages/dashboard";
import GoodForm from "@/pages/good/goodForm";
import GoodList from "@/pages/good/goodList";
import User from "@/pages/user";
import { asyncRoutes } from './pages/index'

//accessRoutes 可访问的路由
//
function createRoutes(accessRoutes) {
    let result = []

    accessRoutes.forEach(route => {
        if (route.path && route.element) {
            result.push(
                <Route key={route.key} path={route.path} element={route.element}></Route>
            )
        }
        if (route.children) {
            route.children.forEach(route => {
                result.push(
                    <Route key={route.key} path={route.path} element={route.element}></Route>
                )
            })
        }
    })
    return result
}

function App() {
    return (
        <HashRouter>
            {/* <Link to='/'>首页</Link> */}
            {/* <Link to='/login'>登录</Link> */}
            <Routes>
                {/* {在React中，一级路由不需要指定出口} */}
                <Route path="/" element={<Layout />}>
                    {/* {二级路由需要指定出口} */}
                    {/* {<Route path="/dashboard" element={<Dashboard />}></Route>
                    <Route path="/good/list" element={<GoodList />}></Route>
                    <Route path="/user" element={<User />}></Route>} */}
                    {
                        createRoutes(asyncRoutes)
                    }
                </Route>
                <Route path="/login" element={<Login />}></Route>

            </Routes>
        </HashRouter>

    );
}
export default App;
